import i18n from './../i18n'
const isFloat = (rule, value, callback) => {
  const reg = /^\d+(\.\d+)?$/
  var result = reg.test(value)
  if (result) {
    callback()
  } else {
    callback(
      i18n.t('validationMessage.specifyInputType', {
        type: i18n.t('validationMessage.float')
      })
    )
  }
}
const numberRange = (rule, value, callback) => {
  isFloat(rule, value, (obj) => {
    if (obj !== undefined) {
      var result =
    parseFloat(rule.min) <= parseFloat(value) &&
    parseFloat(value) <= parseFloat(rule.max)
      if (result) {
        callback()
      } else {
        callback(
          new Error(
            i18n.t('validationMessage.numberRange', {
              min: rule.min,
              max: rule.max
            })
          )
        )
      }
    } else {
      callback(obj)
    }
  })
}
export default { isFloat, numberRange }
